package com.bgs.eat.userAddress.controller;

import com.bgs.eat.userAddress.entity.UserAddressEntity;
import com.bgs.eat.config.CommonResult;
import com.bgs.eat.userAddress.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AddressController
 * @Description TODO
 * @Author hbx
 * @Date 2022/10/25 13:57
 **/
@RestController
@RequestMapping("/userAddress")
@CrossOrigin
public class UserAddressController {

    @Autowired
    UserAddressService addressService;

    /**
    * @Description 获取用户常用地址信息列表（门户用户版）
    * @Author lzy
    * @Date 2022/10/28 14:09
    * @Return com.bgs.eat.config.CommonResult
    * @param userId
    */
    @GetMapping("/getUserProtalAddress")
    public CommonResult getUserProtalAddress(Integer userId){
        return addressService.getUserProtalAddress(userId);
    }

    /**
    * @Author hbx
    * @Description 新增收货地址
    * @Date 2022/10/25 14:11
    * @param addressEntity
    */
    @PostMapping("/addAddress")
    public CommonResult addAddress(@RequestBody UserAddressEntity addressEntity){
        return CommonResult.ok(addressService.addAddress(addressEntity));
    }

    /**
    * @Author hbx
    * @Description 根据用户id查询其他地址信息
    * @Date 2022/10/25 14:40
    * @param userProtalId
    */
    @GetMapping("/getAllAddressByUserId")
    public CommonResult getAllAddressByUserId(Integer userProtalId){
        return CommonResult.ok(addressService.getAllAddressByUserId(userProtalId));
    }

    /**
    * @Author hbx
    * @Description 根据id查询地址信息
    * @Date 2022/10/25 16:36
    * @param id
    */
    @GetMapping("/getAllAdderssById")
    public CommonResult getAllAdderssById(Integer id){
        return CommonResult.ok(addressService.getAllAdderssById(id));
    }

    /**
    * @Author hbx
    * @Description 修改用户地址信息
    * @Date 2022/10/26 9:52
    * @param addressEntity
    */
    @GetMapping("/updateAdderss")
    public CommonResult updateAdderss(UserAddressEntity addressEntity){
        return CommonResult.ok(addressService.updateAdderss(addressEntity));
    }

    /**
    * @Author hbx
    * @Description 根据id删除用户地址信息
    * @Date 2022/10/26 13:54
    * @param id
    */
    @GetMapping("/deleteAddressById")
    public CommonResult deleteAddressById(Integer id){
        return CommonResult.ok(addressService.deleteAddressById(id));
    }

    /**
    * @Author hbx
    * @Description 修改地址类型根据id
    * @Date 2022/10/28 9:57
    * @param id
    */
    @GetMapping("/updateFirstAdderssType")
    public CommonResult updateFirstAdderssType(Integer id){
        return CommonResult.ok(addressService.updateFirstAdderssType(id));
    }
}
